const {defineConfig} = require('@vue/cli-service')
const path = require("path");
const CompressionPlugin = require("compression-webpack-plugin");

function resolve(dir) {
    return path.join(__dirname, dir)
}

process.env.VUE_APP_VERSION = require('./package.json').version

module.exports = defineConfig({
    transpileDependencies: true,
    publicPath: './',
    productionSourceMap: false,
    configureWebpack: {
        devServer: {
            client: {
                overlay: false
            }
        },
        plugins: [
            new CompressionPlugin({
                algorithm: 'gzip',
                // test: /\.js$|\.css$|\.html$/, // 压缩匹配的文件
                test: new RegExp(
                    '\\.(js|css|html|svg|eot|ttf|woff|woff2)$'
                ),
                threshold: 10240, // 对超过10k的数据进行压缩
                minRatio: 0.8, // 最小压缩比达到0.8时结束
                deleteOriginalAssets: false, // 是否删除原文件
            }),
        ]
    },
    chainWebpack: config => {
        config.resolve.alias
            .set('@', resolve('src'))
    },
})
